#include ("/_includes/_layout.html")
#@layout("点步微拼团--模板消息", "wxmall,点步科技", "Wxmall社区","wxmall") 
#define content()
<div class="wrapper wrapper-content">
	<div class="content ibox-content">
		<div class="alert alert-success" style="margin-bottom: 0px;">
			<strong>禁用模板消息后，小程序端将不会接收到微信消息推送</strong>
		</div>
		<div class="panel-body">
			<div style="float: left; margin-right: 20px;">
				<div style="float: left; margin-right: 20px;" >
					<table>
						<tr>
							<td><button id="myBtn" type="button" onclick="synOnline()" class="btn btn-success btn-sm">同步模板</button></td>
						</tr>
					</table>
				</div>
			</div>
		</div>
		<table id="mainTable" class="table table-striped table-bordered bootstrap-datatable datatable" border="0">
		  <thead>
			  <tr>
				<th><input type="checkbox" id="all" title="全选/反选" style="margin-right: 4px; vertical-align: middle;"/></th>
				<th><span style="vertical-align: middle;">&nbsp;&nbsp;模板库id</span></th>
				<th>模板id</th>
				<th>通知类型</th>
				<th>创建时间</th>
				<th>状态</th>
				<th>操作</th>
			  </tr>
		  </thead>   
		  <tbody class="itemsLotGrid">
		  #for(item : msgTemplates)
		  	<tr class="package">
				<td>
					<input type="checkbox" class="commchk" id="checkbox_#(item.id)" style="margin-right: 4px; vertical-align: middle;"/>
					<input type="hidden" value="#(item.id)"/>
				</td>
				<td><span style="margin-right: 5px; margin-left: 2px; vertical-align: middle;">#(item.templateKuId)</span></td>
				<td><span style="margin-right: 5px; margin-left: 2px; vertical-align: middle;">#(item.templateId)</span></td>
				<td><span>#if(item.templateType == 0) 拼团待成团消息
						  #else if(item.templateType == 1) 拼团成功消息
						  #else if(item.templateType == 2) 拼团失败消息 
						  #else if(item.templateType == 3) 支付成功消息 
						  #else if(item.templateType == 4) 订单未支付消息 
						  #else if(item.templateType == 5) 订单支付失败消息 
						  #else if(item.templateType == 6) 订单创建成功消息 
						  #else if(item.templateType == 7) 订单关闭消息 
						  #else if(item.templateType == 8) 订单发货消息 
						  #else if(item.templateType == 9) 预约课程成功通知 
						  #else if(item.templateType == 10) 预约课程失败通知 
						  #else if(item.templateType == 11) 预约考试成功通知 
						  #else if(item.templateType == 12) 预约考试失败通知 
						  #else if(item.templateType == 13) 销售员推广成功通知 
						  #else if(item.templateType == 14) 获得未结算佣金通知 
						  #else if(item.templateType == 15) 砍价进度通知
						  #else 未知通知类型 
						  #end 
					</span></td>
				<td>#(item.created)</td>
				<td><span class="customer_status">#if(item.active == true) 启用  #else <font color="red" style="font-weight: 700;">禁用</font> #end</span></td>
				<td>
					&nbsp;#if(item.active == true) <a id="del_#(item.id)" onclick="del(#(item.id))">禁用</a> #end
					&nbsp;#if(item.active == false)<a id="undel_#(item.id)" onclick="undel(#(item.id))">启用</a> #end
				</td>
			</tr>
		  #else	
			<tr class="package"><td colspan="7" class="center">没有结果集</td></tr>
		  #end
		  </tbody>
	  	</table>
	</div>   
</div>
#end
<script type="text/javascript">
function del(id){
	obz.showMessage("确定禁用模板消息吗？禁用后小程序将不再接收该类型的消息推送！", function(){
		obz.ajaxJson(obz.ctx + "/wxamsgtpl/del", {id: id}, function(resp){
			if(resp.code==200){
				obz.msg("禁用成功", function(){
					location.reload();
				});
			}else {
				obz.error(resp.msg);
			}
		});
	});
}
function undel(id){
	obz.ajaxJson(obz.ctx + "/wxamsgtpl/undel", {id: id}, function(resp){
		if(resp.code==200){
			obz.msg("启用成功", function(){location.reload();});
		}else {
			obz.error(resp.msg);
		}
	});
}
function synOnline(){
	obz.showMessage("确定同步吗？同步后将会清空之前的模板消息！", function(){
		$("#mainTable").mask("正在同步...");
		obz.ajaxJson(obz.ctx + "/wxamsgtpl/synOnline", {}, function(resp){
			if(resp.code==200){
				$("#mainTable").unmask();
				obz.msg("同步成功", function(){
					location.reload();
				});
			}else {
				obz.error(resp.msg);
			}
		});
	});
}
</script>